package com.ostrich.shopping.ui.user.repository;

import com.ostrich.shopping.net.BaseResponseEntity;
import com.ostrich.shopping.net.RetrofitManager;
import com.ostrich.shopping.room.AppDataBase;
import com.ostrich.shopping.room.User;
import com.ostrich.shopping.room.UserDao;
import com.ostrich.shopping.ui.user.UserApi;
import com.ostrich.shopping.ui.user.entity.UserEntity;

import java.util.List;

import androidx.lifecycle.LiveData;
import retrofit2.http.Body;
import retrofit2.http.Query;

/**
 * @Author : yaotianxue
 * @Time : On 2023/9/26 15:26
 * @Description : UserRepository
 */
public class UserRepository {
    private UserApi mUserApi;
    private UserDao mUserDao;
    public UserRepository() {
        mUserApi = RetrofitManager.getInstance().getRetrofit().create(UserApi.class);
        mUserDao = AppDataBase.getInstance().getUserDao();
    }

    public LiveData<BaseResponseEntity<UserEntity>> register( UserEntity user){
        return mUserApi.register(user);
    }

    public LiveData<BaseResponseEntity<UserEntity>> login( String nickname, String password){
        return mUserApi.login(nickname,password);
    }


    //插入用户
    public void insert(User user){
        mUserDao.insert(user);
    }
    //查询用户
    public List<User> getAll(){
        return mUserDao.getAll();
    }






}
